package cn.itcast.ssm.dao;

import cn.itcast.ssm.domain.Member;
import cn.itcast.ssm.domain.Orders;
import cn.itcast.ssm.domain.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface IOrdersDao {
    @Select("select * from orders")
    @Results({
            @Result(id=true, column = "id" ,property = "id"),
            @Result(column = "orderNum", property = "orderNum"),
            @Result(column = "orderTime", property = "orderTime"),
            @Result(column = "peopleCount", property = "peopleCount"),
            @Result(column = "orderDesc", property = "orderDesc"),
            @Result(column = "payType", property = "payType"),
            @Result(column = "orderStatus", property = "orderStatus"),
            @Result(
                    column = "productId",
                    property = "product",
                    javaType = Product.class,
                    one = @One(select = "cn.itcast.ssm.dao.IProductDao.findById"))

    })
    List<Orders> findAll(int currentPage, int pageSize);

    @Select("select * from orders where id=#{oid}")
    @Results({
            @Result(id=true, column = "id" ,property = "id"),
            @Result(column = "orderNum", property = "orderNum"),
            @Result(column = "orderTime", property = "orderTime"),
            @Result(column = "peopleCount", property = "peopleCount"),
            @Result(column = "orderDesc", property = "orderDesc"),
            @Result(column = "payType", property = "payType"),
            @Result(column = "orderStatus", property = "orderStatus"),
            @Result(
                    column = "productId",
                    property = "product",
                    javaType = Product.class,
                    one = @One(select = "cn.itcast.ssm.dao.IProductDao.findById")
            ),
            @Result(
                    column = "memberId",
                    property = "member",
                    javaType = Member.class,
                    one = @One(select = "cn.itcast.ssm.dao.IMemberDao.findById")
            ),
            @Result(
                    column = "id",
                    property = "travellerList",
                    javaType = java.util.List.class,
                    many = @Many(select ="cn.itcast.ssm.dao.ITravellerDao.findByOid")
            )
    })
    Orders findById(String oid);
}
